<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优惠券管理</title>
    <meta name="keywords" content="优惠券管理">
    <meta name="description" content="优惠券管理">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__ADMIN__/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="__ADMIN__/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="__ADMIN__/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__ADMIN__/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="__ADMIN__/css/animate.min.css" rel="stylesheet">
    <link href="__ADMIN__/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <script src="__ADMIN__/js/jquery.min.js?v=2.1.4"></script>
    <script src="__ADMIN__/js/ajaxfileupload.js"></script>
    <link href="__ADMIN__/css/admin.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeIn">
        <div class="row">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="{if condition="input('tab',1) eq 1"}active{/if}"><a data-toggle="tab" href="#tab-1" aria-expanded="true">优惠券列表</a></li>
                        <li class="{if condition="input('tab',1) eq 2"}active{/if}"><a data-toggle="tab" href="#tab-2" aria-expanded="false">添加新优惠券</a></li>
                        <li id="showtab" class="{if condition="input('tab',1) eq 3"}active{/if}"><a data-toggle="tab" href="#tab-3" style="{if condition="input('tab',1) neq 3"}display:none{/if}" aria-expanded="false">编辑优惠券</a></li>
                    </ul>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane {if condition="input('tab',1) eq 1"}active{/if}">
                            <div class="panel-body">
                              <form method="post" class="form-horizontal" data-type="ajax">
                                  <div class="table-responsive">
                                      <table id="dataTables-example" class="table table-striped">
                                          <thead>
                                              <tr>
                                                  <th>ID</th>
                                                  <th>优惠券名称</th>
                                                  <th>优惠券类型</th>
                                                  <th>优惠方式</th>
                                                  <th>最低消费金额</th>
                                                  <th>有效期</th>
                                                  <th>已领取数量</th>
                                                  <th>排序</th>
                                                  <th>操作</th>
                                              </tr>
                                          </thead>
                                      </table>
                                  </div>
                              </form>
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane {if condition="input('tab',1) eq 2"}active{/if}">
                            <div class="panel-body">
                                <form method="post" class="form-horizontal" action="{:url('add')}" data-type="ajax">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">优惠券名称</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='name' class="form-control" value="">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">类型</label>
                                        <div class="col-sm-10">
                                            <div class="radio i-checks">
                                                <label><input id="price-coupon" type="radio" value="0" name="type" checked><i></i> 满减券</label>
                                                <label><input id="discount-coupon" type="radio" value="1" name="type"><i></i> 折扣券</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group price-coupon">
                                        <label class="col-sm-2 control-label">减免金额</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='price' class="form-control" value="">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed price-coupon"></div>

                                    <div class="form-group discount-coupon" style="display:none">
                                        <label class="col-sm-2 control-label">折扣率</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='discount' class="form-control" value="">
                                            <span class="help-block m-b-none">折扣率范围1-100</span>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed discount-coupon" style="display:none"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">最低消费金额</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='min_price' class="form-control" value="">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">生效时间</label>
                                        <div class="col-sm-10">
                                            <input class="form-control layer-date" name="start_time" value="{:date('Y-m-d')}" onclick="laydate({format: 'YYYY-MM-DD'})">
                                            <label class="laydate-icon"></label>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">截止时间</label>
                                        <div class="col-sm-10">
                                            <input class="form-control layer-date" name="end_time" value="{:date('Y-m-d')}" onclick="laydate({format: 'YYYY-MM-DD'})">
                                            <label class="laydate-icon"></label>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">排序</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='sort' class="form-control" value="">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn btn-primary" type="submit">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div id="tab-3" class="tab-pane {if condition="input('tab',1) eq 3"}active{/if}">
                            <div class="panel-body">
                                <form method="post" class="form-horizontal" action="{:url('edit')}" data-type="ajax">
                                    <input type="hidden" name="tab" value="3">
                                    <input type="hidden" name="id" value="{$info.id}">

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">优惠券名称</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='name' class="form-control" value="{$info.name}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">类型</label>
                                        <div class="col-sm-10">
                                            <div class="radio i-checks">
                                                <label><input id="price-coupon_edit" type="radio" value="0" name="type" {$info.type ? '' : 'checked'}><i></i> 满减券</label>
                                                <label><input id="discount-coupon_edit" type="radio" value="1" name="type" {$info.type ? 'checked' : ''}><i></i> 折扣券</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group price-coupon_edit">
                                        <label class="col-sm-2 control-label">减免金额</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='price' class="form-control" value="{$info.price}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed price-coupon_edit"></div>

                                    <div class="form-group discount-coupon_edit" style="display:none">
                                        <label class="col-sm-2 control-label">折扣率</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='discount' class="form-control" value="{$info.discount}">
                                            <span class="help-block m-b-none">折扣率范围1-100</span>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed discount-coupon_edit" style="display:none"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">最低消费金额</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='min_price' class="form-control" value="{$info.min_price}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">生效时间</label>
                                        <div class="col-sm-10">
                                            <input class="form-control layer-date" name="start_time" value="{:date('Y-m-d', $info.start_time)}" onclick="laydate({format: 'YYYY-MM-DD'})">
                                            <label class="laydate-icon"></label>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">截止时间</label>
                                        <div class="col-sm-10">
                                            <input class="form-control layer-date" name="end_time" value="{:date('Y-m-d', $info.end_time)}" onclick="laydate({format: 'YYYY-MM-DD'})">
                                            <label class="laydate-icon"></label>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">排序</label>
                                        <div class="col-sm-10">
                                            <input type="text" name='sort' class="form-control" value="{$info.sort}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn btn-primary" type="submit">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="__ADMIN__/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="__ADMIN__/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="__ADMIN__/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="__ADMIN__/js/content.min.js?v=1.0.0"></script>
    <script src="__ADMIN__/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__ADMIN__/js/plugins/layer/layer.min.js"></script>
    <script src="__ADMIN__/js/layer_hplus.js"></script>
    <script src="__ADMIN__/js/plugins/layer/laydate/laydate.js"></script>
    <script>
        $(document).ready(function() {

            var type = {$info.type ? $info.type : '0'};
            if(type == '1'){
                $(".discount-coupon_edit").show();
                $(".price-coupon_edit").hide();
            }

            $("#dataTables-example").on('click', 'a.coupon_edit', function(){
                var id = $(this).attr('id');
                var receive_num = $(this).attr('receive_num');
                if(receive_num > 0){
                  layer.open({
                      content:'已有会员领取，无法编辑',
                      shade:0.1,
                      btn: ['确定'],
                      icon: 2
                  });
                }else{
                  location.href = "{:url('/admin/coupon/index/id/" + id + "/tab/3')}";
                }
            });

            $("#dataTables-example").dataTable({
                "bAutoWidth": false,
                "serverSide": true,
                "ajax": {
                    "url": "{:url('getDataTables')}",
                    "data": function(d) {
                        d.extra_search = "name";
                    }
                },
                "ordering": false, //禁用全局排序
                "order": [0, '`id` desc'],
                "lengthMenu": [10, 20, 50, 100],
                "dom": "<'row'<'#normalToos.col-xs-4'><'col-xs-8'f>>" +
                    "<'row'<'col-xs-12't>>" +
                    "<'row'<'col-xs-6'li><'col-xs-6'p>>",
                "language": {
                    "zeroRecords": "没有检索到数据",
                    "lengthMenu": "每页 _MENU_ 条记录&nbsp;&nbsp;",
                    "search": "搜索 ",
                    "info": "共 _PAGES_ 页，_TOTAL_ 条记录，当前显示 _START_ 到 _END_ 条",
                    "paginate": {
                        "previous": "上一页",
                        "next": "下一页",
                    }
                },
                "columns": [{
                    data: "id"
                }, {
                    data: "name"
                }, {
                    data: "type"
                }, {
                    data: "discount_type"
                }, {
                    data: "min_price"
                }, {
                    data: "expiry_date"
                }, {
                    data: "receive_num"
                }, {
                    data: "sort"
                }, {
                    data: "operate"
                }, ],
                "drawCallback": function() {
                    normal_init();
                }
            });

        });
    </script>
</body>

</html>
